﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GKQC.Common
{
    public class TestContext
    {
        public SqlSugarClient db;
        DbType dbType = DbType.SqlServer;
        public TestContext(string s1, DbType dbType)
        {
            //Logger.LogMessage("orclStringTest:\r\n" + s1);
            this.dbType = dbType;
            db = new SqlSugarClient(
                new ConnectionConfig()
                {
                    ConnectionString = s1,
                    DbType = dbType,//设置数据库类型
                    IsAutoCloseConnection = true,//自动释放数据务，如果存在事务，在事务结束后释放
                    InitKeyType = InitKeyType.Attribute //从实体特性中读取主键自增列信息

                   
                }
            );
        }

        public bool Test()
        {
            bool flag = false;
            string sql = string.Empty;
            if(this.dbType == DbType.SqlServer)
            {
                sql = "select 1";
            }
            else if(this.dbType == DbType.Oracle)
            {
                sql = "select 1 from dual";
            }
            else
            {
                throw new Exception("不支持的數據庫類型");
            }

            try
            {
                db.Ado.GetDataTable(sql);
                flag = true;
            }
            catch(Exception ex)
            {
                Logger.LogError(ex);
                throw ex;
            }


            return flag;
        }
    }
}
